Expose the method-listing call as host.list_methods.
authorEwan Mellor <ewan@xensource.com>
Wed, 4 Apr 2007 17:42:20 +0000 (18:42 +0100)
committerEwan Mellor <ewan@xensource.com>
Wed, 4 Apr 2007 17:42:20 +0000 (18:42 +0100)
Signed-off-by: Ewan Mellor <ewan@xensource.com>
docs/xen-api/xenapi-datamodel.tex
tools/libxen/include/xen_host.h
tools/libxen/src/xen_host.c
tools/libxen/test/test_bindings.c
tools/python/xen/xend/XendAPI.py
tools/python/xen/xm/main.py

index ed67328ec5b0c88055d7c870f0c5090521127166..eadcf7e3f46b97b6c4212d858ffdd1ff25302cec 100644 (file)
@@ -4952,6 +4952,27 @@ dmesg string
 \vspace{0.3cm}
 \vspace{0.3cm}
 \vspace{0.3cm}
+\subsubsection{RPC name:~list\_methods}
+
+{\bf Overview:} 
+List all supported methods.
+
+ \noindent {\bf Signature:} 
+\begin{verbatim} (string Set) list_methods (session_id s)\end{verbatim}
+
+
+\vspace{0.3cm}
+
+ \noindent {\bf Return Type:} 
+{\tt 
+string Set
+}
+
+
+The name of every supported method.
+\vspace{0.3cm}
+\vspace{0.3cm}
+\vspace{0.3cm}
 \subsubsection{RPC name:~get\_all}
 
 {\bf Overview:} 
index f9919ad309efa558a96fb3179b860be1e920b249..1fbe0143258f056422864e6b67e3e251b4b6fc1c 100644 (file)
@@ -435,6 +435,13 @@ extern bool
 xen_host_dmesg(xen_session *session, char **result, xen_host host);
 
 
+/**
+ * List all supported methods.
+ */
+extern bool
+xen_host_list_methods(xen_session *session, struct xen_string_set **result);
+
+
 /**
  * Return a list of all the hosts known to the system.
  */
index 64badac031a0ce2764a13dfb1b42c91808cd939e..d46f061c30af4349a9b839e03115969cfc7f8db5 100644 (file)
@@ -739,6 +739,18 @@ xen_host_dmesg(xen_session *session, char **result, xen_host host)
 }
 
 
+bool
+xen_host_list_methods(xen_session *session, struct xen_string_set **result)
+{
+
+    abstract_type result_type = abstract_type_string_set;
+
+    *result = NULL;
+    xen_call_(session, "host.list_methods", NULL, 0, &result_type, result);
+    return session->ok;
+}
+
+
 bool
 xen_host_get_all(xen_session *session, struct xen_host_set **result)
 {
index 68f7985f9dd57cc4cae8700f9e4400c4f4d01602..6da442d53971b600bba7e2a564f2fb56db2390cb 100644 (file)
@@ -64,6 +64,7 @@ typedef struct
 
 static xen_vm create_new_vm(xen_session *session, bool hvm);
 static void print_session_info(xen_session *session);
+static void print_methods(xen_session *session);
 static void print_vm_power_state(xen_session *session, xen_vm vm);
 static void print_vm_metrics(xen_session *session, xen_vm vm);
 
@@ -166,6 +167,14 @@ int main(int argc, char **argv)
         return 1;
     }
 
+    print_methods(session);
+    if (!session->ok)
+    {
+        /* Error has been logged, just clean up. */
+        CLEANUP;
+        return 1;
+    }
+
     xen_vm vm;
     if (!xen_vm_get_by_uuid(session, &vm,
                             "00000000-0000-0000-0000-000000000000"))
@@ -644,6 +653,40 @@ static void print_session_info(xen_session *session)
 }
 
 
+static int pstrcmp(const void *p1, const void *p2)
+{
+    return strcmp(*(char **)p1, *(char **)p2);
+}
+
+
+/**
+ * Print the list of supported methods.
+ */
+static void print_methods(xen_session *session)
+{
+    xen_string_set *methods;
+
+    if (!xen_host_list_methods(session, &methods))
+    {
+        print_error(session);
+        goto done;
+    }
+
+    printf("%zd.\n", methods->size);
+    qsort(methods->contents, methods->size, sizeof(char *), pstrcmp);
+
+    printf("Supported methods:\n");
+    for (size_t i = 0; i < methods->size; i++)
+    {
+        printf("  %s\n", methods->contents[i]);
+    }
+    fflush(stdout);
+
+done:
+    xen_string_set_free(methods);
+}
+
+
 /**
  * Print the metrics for the given VM.
  */
index 9c7b9a461a8cd0f81f94567e1560ada2ac015534..cd7511588eea7c6ac313c4455dfc2fa40ec0057a 100644 (file)
@@ -886,7 +886,8 @@ class XendAPI(object):
                     ('get_log', 'String'),
                     ('send_debug_keys', None)]
     
-    host_funcs = [('get_by_name_label', 'Set(host)')]
+    host_funcs = [('get_by_name_label', None),
+                  ('list_methods', None)]
 
     # attributes
     def host_get_name_label(self, session, host_ref):
@@ -1010,6 +1011,12 @@ class XendAPI(object):
             return xen_api_success((XendNode.instance().uuid,))
         return xen_api_success([])
     
+    def host_list_methods(self, _):
+        def _funcs():
+            return [getattr(XendAPI, x) for x in XendAPI.__dict__]
+
+        return xen_api_success([x.api for x in _funcs()
+                                if hasattr(x, 'api')])
 
     # Xen API: Class host_CPU
     # ----------------------------------------------------------------
@@ -2611,15 +2618,6 @@ class XendAPI(object):
         return xen_api_success({'uuid': debug_ref})
 
 
-    def list_all_methods(self, _):
-        def _funcs():
-            return [getattr(XendAPI, x) for x in XendAPI.__dict__]
-
-        return xen_api_success([x.api for x in _funcs()
-                                if hasattr(x, 'api')])
-    list_all_methods.api = '_UNSUPPORTED_list_all_methods'
-
-
 class XendAPIAsyncProxy:
     """ A redirector for Async.Class.function calls to XendAPI
     but wraps the call for use with the XendTaskManager.
index 940a97034e372302ea612e8926c2cf0da7ab3bab..5a6a5feca738a41e3f6d8a336c7b9412dd56fb64 100644 (file)
@@ -591,7 +591,7 @@ class Shell(cmd.Cmd):
         self.prompt = "xm> "
         if serverType == SERVER_XEN_API:
             try:
-                res = server.xenapi._UNSUPPORTED_list_all_methods()
+                res = server.xenapi.host.list_methods()
                 for f in res:
                     setattr(Shell, 'do_' + f + ' ', self.default)
             except: